/*

	This file prepares regressions sample at firm-destination-year level with grpuped support categories

*/

cd ${work}5_reg_analysis

use input\sample_idt if year>2002 , clear

*EXPORT
preserve
	use input\export_ipdt, clear
	collapse (sum) vrd_exp_exsmall , by(jurnr land year)
	save temp\temp, replace
restore
merge 1:1 jurnr land year using temp\temp, keep(1 3) keepusing(vrd_exp_exsmall) nogen
erase temp\temp.dta
replace vrd_exp_exsmall=0 if vrd_exp_exsmall==.

*PROMOTION
destring jurnr, gen(jurnr_num)
merge 1:1 jurnr_num land year using input\promotion_idt, keep(1 3) keepusing(treated_2 tdcinitiative_2) nogen
merge 1:1 jurnr_num land year using input\promotion_product_idt, keep(1 3) keepusing(treated_p*_2 tdcinitiative_p*_2) nogen
drop jurnr_num
foreach v of varlist treated_2 tdcinitiative_2 treated_p*_2 tdcinitiative_p*_2 {
    replace `v'=0 if `v'==.
}

lab var treated_p1_2	"Partner Search etc."
lab var treated_p2_2	"Fairs etc."
lab var treated_p3_2	"Intelligence etc."
lab var treated_p4_2	"Commercial Assistance"
lab var treated_p5_2	"Everything else"

*INDUSTRY CODES
merge m:1 jurnr year using input\firm_it, assert(2 3) keep(3) keepusing(nace4) nogen

*SPECIFICATOINS
winsor2 vrd_exp_exsmall if vrd_exp_exsmall>0 , cuts(0 99) replace
gen log_vrd_exp_exsmall=log(vrd_exp_exsmall)
gen exp_status = (vrd_exp_exsmall>0)

lab var log_vrd_exp_exsmall	"ln(EXV)"
lab var exp_status			"EXP"

*FEs
egen IDY=group(nace4 land year)
egen FY=group(jurnr year)
egen FD=group(jurnr land)
egen F=group(jurnr)

*SAVE
compress
save temp\regsample_product_idt, replace